<?php
	namespace Common\Logic;
	use Common\Model\NewsModel;
	class NewsLogic extends NewsModel{
		/*
		* Function:		getNewsList
		* Description:	新闻列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getNewsList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getNewsFilter($filter);
			return $this->where($conditon)->order('sort desc,id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getNewsFilter
		* Description:	新闻列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getNewsFilter($filter = ''){
			$conditon = array();
			$conditon['status'] = 1;
			if(!empty($filter['title'])){
				$conditon['title'] = array('like','%'.$filter['title'].'%');
			}
			if(!empty($filter['tid'])){
				$conditon['tid'] = $filter['tid'];
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getNewsCount
		* Description:	新闻列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getNewsCount($filter = ''){
			$conditon = $this->getNewsFilter($filter);
			return $this->where($conditon)->count();
		}
		
		/*
		* Function:		addNews
		* Description:	增加新闻
		* @param:		$data array 增加的数组
		*/
		public function addNews($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getNewsInfo
		* Description:	获取新闻信息 by row
		* @param:		$id int ID
		*/
		public function getNewsInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateNews
		* Description:	更新新闻
		* @param:		$data array 更新的数组
		*/
		public function updateNews($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteNews
		* Description:	删除新闻
		* @param:		$id int ID
		*/
		public function deleteNews($id){
			return $this->where(array('id'=>$id))->delete();
		}
	}
?>